home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Gfx / Edit / TSMorph / src / LoadBrushes.c < prev    next >
C/C++ Source or Header  |  1994-10-30  |  5KB  |  172 lines

  1. // TSMorph - Amiga Morphing program
  2. // Copyright (C) © 1993  Topicsave Limited
  3.  
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // any later version.
  8.  
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13.  
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. // mpaddock@cix.compulink.co.uk
  19.  
  20. // include precompiled header if not already
  21. #ifndef TSMOPRH_H
  22. #include "TSMorph.h"
  23. #endif
  24.  
  25. /* version of loadbrush which first check file exists
  26.  * to prevent any error message being displayed if not present
  27.  */
  28. int
  29. myloadbrush(struct ILBMInfo *info,UBYTE *filename) {
  30.     BPTR fh;
  31.     if (fh = Open(filename,MODE_OLDFILE)) {
  32.         Close(fh);
  33.         return loadbrush(info,filename);
  34.     }
  35.     return 1;
  36. }
  37.  
  38. /* load a pointer from a 4 colour ILBM file.
  39.  *
  40.  * ilbm     - ILBM stuff
  41.  * address  - address to store sprite
  42.  * filename - name of iff file to load
  43.  */
  44. void
  45. mycopysprite(struct ILBMInfo *ilbm,UWORD *address,UBYTE *filename) {
  46.     int i;
  47.     UWORD *p0,*p1,*o0;
  48.     // try and load brush first
  49.     if (!myloadbrush(ilbm,filename)) {
  50.         // if ok then convert to pointer format
  51.         p0 = (UWORD *)ilbm->brbitmap->Planes[0];
  52.         p1 = (UWORD *)ilbm->brbitmap->Planes[1];
  53.         o0 = address + 2;
  54.         for (i = 0;
  55.               i < 32;
  56.               ++i) {
  57.             *o0++ = *p0++;
  58.             *o0++ = *p1++;
  59.         }
  60.     }
  61.     // close and unload brush
  62.     closeifile(&(ilbm->ParseInfo));
  63.     unloadbrush(ilbm);
  64. }
  65.  
  66. /* load an image from a 4 colour ILBM file
  67.  *
  68.  * ilbm     - ILBM stuff
  69.  * im       - pointer to image to store data
  70.  * filename - name of iff file to load
  71.  * size     - size of image bit plane
  72.  */
  73. void
  74. mycopybrush(struct ILBMInfo *ilbm,struct Image *im,UBYTE *filename,UWORD size) {
  75.     // try and load brush first
  76.     if (!myloadbrush(ilbm,filename)) {
  77.         // if ok then copy to image data
  78.         CopyMem(im->ImageData,ilbm->brbitmap->Planes[0],size);
  79.         CopyMem(((UBYTE *)im->ImageData)+size,ilbm->brbitmap->Planes[1],size);
  80.     }
  81.     // close and unload brush
  82.     closeifile(&(ilbm->ParseInfo));
  83.     unloadbrush(ilbm);
  84. }
  85.  
  86. /* Invert an image for a highlighted gadget
  87.  * this is used rather than complement to look good on >4 colour screen
  88.  * (There must be a better way)
  89.  *
  90.  * im    - Image pointer, note that the memory for the image data is twice the required size
  91.  * size  - size of image data
  92.  */
  93. void
  94. invertbrush(struct Image *im,UWORD size) {
  95.     UWORD *a,*b;
  96.     UWORD i;
  97.     a = im->ImageData,
  98.     b = im->ImageData+size;
  99.     for (i = 0;
  100.           i < size;
  101.           i++) {
  102.         *b++ = ~*a++;
  103.     }
  104. }
  105.  
  106. /* Load pointer and
  107.  * gadget images
  108.  */
  109. void
  110. LoadBrushes(void) {
  111.     struct ILBMInfo    ilbm = {0};        // ILBM info for iff read
  112.     BPTR                     lock, cd;        // lock on new directory and old directory
  113.     if (ilbm.ParseInfo.iff = AllocIFF()) {    // get IFF stuff
  114.         ilbm.ParseInfo.propchks = props;        // and initialise chunks required
  115.         ilbm.ParseInfo.collectchks = nowt;
  116.         ilbm.ParseInfo.stopchks = stops;
  117.         if (lock = Lock("TSMorph:brush",ACCESS_READ)) {    // try and change to this directory
  118.             cd = CurrentDir(lock);
  119.             // Load all image files
  120.             mycopybrush(&ilbm,&Add_im,"add",204);
  121.             mycopybrush(&ilbm,&Del_im,"del",204);
  122.             mycopybrush(&ilbm,&Link_im,"link",204);
  123.             mycopybrush(&ilbm,&None_im,"none",204);
  124.             mycopybrush(&ilbm,&One_im,"one",204);
  125.             mycopybrush(&ilbm,&Rel_im,"rel",204);
  126.             mycopybrush(&ilbm,&Two_im,"two",204);
  127.             mycopybrush(&ilbm,&Unlink_im,"unlink",204);
  128.             mycopybrush(&ilbm,&st_im,"1st",30);
  129.             mycopybrush(&ilbm,&prev_im,"prev",30);
  130.             mycopybrush(&ilbm,&goto_im,"goto",30);
  131.             mycopybrush(&ilbm,&next_im,"next",30);
  132.             mycopybrush(&ilbm,&last_im,"last",30);
  133.             // switch back to old dir
  134.             CurrentDir(cd);
  135.             UnLock(lock);
  136.         }
  137.         // invert all gadgets for hilite
  138.         invertbrush(&Add_im,204);
  139.         invertbrush(&Del_im,204);
  140.         invertbrush(&Link_im,204);
  141.         invertbrush(&None_im,204);
  142.         invertbrush(&One_im,204);
  143.         invertbrush(&Rel_im,204);
  144.         invertbrush(&Two_im,204);
  145.         invertbrush(&Unlink_im,204);
  146.         invertbrush(&st_im,30);
  147.         invertbrush(&prev_im,30);
  148.         invertbrush(&goto_im,30);
  149.         invertbrush(&next_im,30);
  150.         invertbrush(&last_im,30);
  151.         if (lock = Lock("TSMorph:cursor",ACCESS_READ)) {    // try and change to this directory
  152.             cd = CurrentDir(lock);
  153.             // Load all pointer files
  154.             mycopysprite(&ilbm,Add,"XAdd");
  155.             mycopysprite(&ilbm,Del,"XDel");
  156.             mycopysprite(&ilbm,L1,"XL1");
  157.             mycopysprite(&ilbm,L2,"XL2");
  158.             mycopysprite(&ilbm,Mov,"XMov");
  159.             mycopysprite(&ilbm,One,"XOne");
  160.             mycopysprite(&ilbm,Rel,"XRel");
  161.             mycopysprite(&ilbm,Two,"XTwo");
  162.             mycopysprite(&ilbm,U1,"XU1");
  163.             mycopysprite(&ilbm,U2,"XU2");
  164.             // switch back to old dir
  165.             CurrentDir(cd);
  166.             UnLock(lock);
  167.         }
  168.         // free IFF stuff
  169.         FreeIFF(ilbm.ParseInfo.iff);
  170.     }
  171. }    
  172.